#include "teachpage.h"
#include "ui_teachpage.h"
#include "mainWidget.h"

TeachPage::TeachPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TeachPage)
{
    ui->setupUi(this);

    this->init();

    pWidget = static_cast<Widget*>(parent);

    /////////////////////////////编辑对话框开始/////////////////////////////
    connect(ui->Btn_mainProg, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(MainProg_id);
    });
    connect(ui->Btn_subProg, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(SubProg_id);
    });
    connect(ui->Btn_axisMove, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(AxisMove_id);
    });
    connect(ui->Btn_incMotion, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(IncMotion_id);
    });
    connect(ui->Btn_stackPos, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(StackPos_id);
    });
    connect(ui->Btn_stackCnt, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(StackCnt_id);
    });
    connect(ui->Btn_userVar, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(UserVar_id);
    });
    connect(ui->Btn_pulseWidthOutput, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(PulseWidthOutput_id);
    });
    connect(ui->Btn_judgeCond, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(JudgeCond_id);
    });
    connect(ui->Btn_loopCond, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(LoopCond_id);
    });
    connect(ui->Btn_jump, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(Jump_id);
    });
    connect(ui->Btn_delay, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(Delay_id);
    });
    connect(ui->Btn_otherwise, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(Otherwise_id);
    });
    connect(ui->Btn_specialCmd, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(SpecialCmd_id);
    });
    connect(ui->Btn_outputDetect, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(OutputDetect_id);
    });
    connect(ui->Btn_searchMotion, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(SearchMotion_id);
    });
    connect(ui->Btn_machBack0, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(MachBack0_id);
    });
    connect(ui->Btn_coordRst, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(CoordRst_id);
    });
    connect(ui->Btn_slowDownPoint, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(SlowDownPoint_id);
    });
    connect(ui->Btn_interpolationStart, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(InterpolationStart_id);
    });
    connect(ui->Btn_advConfirm, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(AdvConfirm_id);
    });
    connect(ui->Btn_lineInterpolation, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(LineInterpolation_id);
    });
    connect(ui->Btn_transPoint, &QPushButton::clicked, this, [=](){
        pWidget->showEditTeach(TransPoint_id);
    });
    ////////////////////////////////////////编辑对话框结束////////////////////////////////////////

    connect(ui->Btn_outputCtl, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_teach->setCurrentIndex(Output_id);
        ui->Btn_loaclOutputPort->setStyleSheet("background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #00BEFA, stop: 1 #0160EA);");
    });
    connect(ui->Btn_OutPageUp, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_output->setCurrentIndex(0);
    });
    connect(ui->Btn_OutPageDown, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_output->setCurrentIndex(1);
    });
    connect(ui->Btn_OutputBack, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_teach->setCurrentIndex(Prog_id);
    });
    connect(ui->Btn_inputDetect, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_teach->setCurrentIndex(Input_id);
        ui->Btn_localInputPort->setStyleSheet("background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #00BEFA, stop: 1 #0160EA);");
    });
    connect(ui->Btn_InPageUp, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_input->setCurrentIndex(0);
    });
    connect(ui->Btn_InPageDown, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_input->setCurrentIndex(1);
    });
    connect(ui->Btn_InputBack, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_teach->setCurrentIndex(Prog_id);
    });
}

TeachPage::~TeachPage()
{
    delete ui;
}

void TeachPage::init()
{
    ui->stackedWidget_teach->setCurrentIndex(Prog_id);
    ui->stackedWidget_menu->setCurrentIndex(MainMenu_id);
    ui->stackedWidget_input->setCurrentIndex(0);
    ui->stackedWidget_output->setCurrentIndex(0);

    bPush0 = bPush1 = false;
}

//基本指令和轴控指令之间的逻辑控制处理
void TeachPage::on_Btn_basicCmd_clicked()
{
    bPush0 = !bPush0;
    if(bPush0)
    {
        ui->stackedWidget_menu->setCurrentIndex(BasicCmd_id);
        ui->Btn_basicCmd->setStyleSheet("background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #00BEFA, stop: 1 #0160EA);");
        ui->Btn_axisCtlCmd->setStyleSheet("background-color:#F2F2F2;");
        bPush1 = false;
    }
    else
    {
        ui->stackedWidget_menu->setCurrentIndex(MainMenu_id);
        ui->Btn_basicCmd->setStyleSheet("background-color:#F2F2F2;");
    }
}

//轴控指令和基本指令之间的逻辑控制处理
void TeachPage::on_Btn_axisCtlCmd_clicked()
{
    bPush1= !bPush1;
    if(bPush1)
    {
        ui->stackedWidget_menu->setCurrentIndex(AxisCtlCmd_id);
        ui->Btn_axisCtlCmd->setStyleSheet("background-color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 #00BEFA, stop: 1 #0160EA);");
        ui->Btn_basicCmd->setStyleSheet("background-color:#F2F2F2;");
        bPush0 = false;
    }
    else
    {
        ui->stackedWidget_menu->setCurrentIndex(MainMenu_id);
        ui->Btn_axisCtlCmd->setStyleSheet("background-color:#F2F2F2;");
    }
}

